import { fileURLToPath, URL } from 'node:url'
import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // vueDevTools(),
    AutoImport({
      imports: ['vue', 'vue-router'],
      resolvers: [ElementPlusResolver()]
    }),
  ],
  server: {
    // host: '192.168.1.20',
    // host: '192.168.1.26',
     host: '127.0.0.1',
    // host: '0.0.0.0',
    port: 4645,
    open: true,
    proxy: {
      '/api': {
        // target: `http://127.0.0.1:9200`,
        target: 'http://127.0.0.1:9800',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      },
    },
    // cors: true,
  },
  resolve: {
    alias: {
      // '@': fileURLToPath(new URL('./src', import.meta.url))
      '@': path.resolve(__dirname, 'src'),
    },
  },
  css: {
    devSourcemap: true,
  }
})
